package com.bdsc.blogs.mirror.entity;

import com.bdsc.blogs.mirror.enumerate.ArticleStatus;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 马凯林
 */
@EntityListeners(AuditingEntityListener.class)
@Table(name = "ARTICLE")
@Entity
public class Article {

  private Integer id;
  private String title;
  private String content;
  private String creator;
  private Date createTime;
  private Date updateTime;
  private Classify classify;
  private String comment;
  private Integer pageView;
  private byte[] showPic;
  private Set<Keyword> keywords = new HashSet<>();
  private ArticleStatus status;
  private Boolean top;
  private Boolean original;
  private String originalLink;
  private Boolean privately;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  @Lob
  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }

  @Column(length = 30)
  public String getCreator() {
    return creator;
  }

  public void setCreator(String creator) {
    this.creator = creator;
  }

  @CreatedDate
  @Temporal(TemporalType.TIMESTAMP)
  public Date getCreateTime() {
    return createTime;
  }

  public void setCreateTime(Date createTime) {
    this.createTime = createTime;
  }

  @LastModifiedDate
  @Temporal(TemporalType.TIMESTAMP)
  public Date getUpdateTime() {
    return updateTime;
  }

  public void setUpdateTime(Date updateTime) {
    this.updateTime = updateTime;
  }

  /**
   * 单向多对一
   */
  @JoinColumn(name = "CLASSIFY_ID")
  @ManyToOne
  public Classify getClassify() {
    return classify;
  }

  public void setClassify(Classify classify) {
    this.classify = classify;
  }

  @Column(length = 150)
  public String getComment() {
    return comment;
  }

  public void setComment(String comment) {
    this.comment = comment;
  }

  public Integer getPageView() {
    return pageView;
  }

  public void setPageView(Integer pageView) {
    this.pageView = pageView;
  }

  @Lob
  public byte[] getShowPic() {
    return showPic;
  }

  public void setShowPic(byte[] showPic) {
    this.showPic = showPic;
  }

  /**
   * 双向多对多
   */
  @JoinTable(
      name = "ARTICLE_KEYWORD",
      joinColumns = {@JoinColumn(name = "ARTICLE_ID", referencedColumnName = "ID")},
      inverseJoinColumns = {@JoinColumn(name = "KEYWORD_ID", referencedColumnName = "ID")})
  @ManyToMany
  public Set<Keyword> getKeywords() {
    return keywords;
  }

  public void setKeywords(Set<Keyword> keywords) {
    this.keywords = keywords;
  }

  @Enumerated(EnumType.STRING)
  @Column(name = "status")
  public ArticleStatus getStatus() {
    return status;
  }

  public void setStatus(ArticleStatus status) {
    this.status = status;
  }

  public Boolean getTop() {
    return top;
  }

  public void setTop(Boolean top) {
    this.top = top;
  }

  public Boolean getOriginal() {
    return original;
  }

  public void setOriginal(Boolean original) {
    this.original = original;
  }

  public String getOriginalLink() {
    return originalLink;
  }

  public void setOriginalLink(String originalLink) {
    this.originalLink = originalLink;
  }

  public Boolean getPrivately() {
    return privately;
  }

  public void setPrivately(Boolean privately) {
    this.privately = privately;
  }
}
